@extends('admin.admin')

@section('content')
        <!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        商品管理
        <small>活动专题</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="/admin"><i class="fa fa-dashboard"></i> 控制面板</a></li>
        <li ><a href="/admin/activity">活动管理</a></li>
        <li class="active">活动专题</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="row">
        <div class="col-xs-12">
            <div class="box box-primary ">
                <div class="box-body table-responsive">
                    <a href="{{route('admin.activity.create')}}" class="btn btn-success"><i class="icon glyphicon glyphicon-plus"></i>添加</a>

                    {!! Form::model(@$shop,array('route' => 'admin.activity.index','method' => 'get','class'=>'form-search form-inline pull-right')) !!}
                    <div class="form-group">
                        {!! Form::text('name',$search['name'],['class'=>'form-control','placeholder'=>'活动名称'])!!}
                    </div>
                    <button type="submit" class="btn btn-primary">搜索</button>
                    <button type="button" onclick="window.location.href='/admin/activity'" class="btn btn-default">重置</button>
                    {!! Form::close() !!}
                </div>
            </div><!-- end .box box-primary -->
            {!! Form::model($activitys,array('route' => 'admin.activity.sort','class'=>'form-horizontal')) !!}
            <div class="box box-primary">
                <div class="box-header">
                    <h3 class="box-title">活动专题</h3>

                    <div class="pull-right">
                        <a href="{{route('admin.activity.create')}}" type="button" class="btn btn-block"><i class="icon  glyphicon glyphicon-plus"></i> 添加</a>

                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">

                    <table class="table table-hover no-margin">
                        <tr>
                            <th style="width:50px;">排序</th>
                            <th style="width:50px;">ID</th>

                            <th>活动名称</th>
                            <th>描述</th>      
                            <th>添加时间</th>
                            <th>活动页标识</th>
                            <th>是否推荐</th>
                            <th style="width: 290px;">操作</th>

                        </tr>
                        @foreach ($activitys as $activity)
                        <tr>
                            <td>{!! Form::text('sort_order['.$activity->id.']',$activity->sort_order,['class'=>'input-mini','style'=>'text-align:center;width: 30px;height:30px;margin-bottom:0px;'])!!}</td>
                            <td>{{$activity->id}}</td>
                            <td>{{$activity->name}}</td>
                            <td>{{$activity->description}}</td>            
                            <td>{{$activity->add_time}}</td>
                            <!-- <td>{{$activity->is_show}}</td> -->
                            <!-- <td>
                                @if($activity->is_show==0)
                                不展示
                                @else
                                展示
                                @endif
                            </td> -->
                            <td>{{$activity->identification}}</td>
                            <td width="9%" style="text-align: center" class="is_recommend" id="{{$activity->id}}" is_recommend="{{$activity->is_recommend}}">@if($activity->is_recommend==1)
                                    <i  class="glyphicon glyphicon-ok " style=" cursor: pointer;color: green;"></i>
                                @else
                                    <i  class="glyphicon glyphicon-remove " style=" cursor: pointer;color: red;"></i>
                                @endif
                            </td>

                            <td>
                                <!-- <a href="/admin/activity/{{$activity->id}}/0/goods" type="button" class="btn  btn-default btn-xs"><i class="icon  glyphicon glyphicon-edit"></i> 商品管理</a> -->

                                <a href="{{Route('admin.activity_cat.index')}}?id={{$activity->id}}" type="button" class="btn  btn-default btn-xs"><i class="icon  glyphicon glyphicon-edit"></i> 专题分类</a>
                                <a href="{{Route('admin.activity.edit',$activity->id)}}" type="button" class="btn  btn-default btn-xs"><i class="icon  glyphicon glyphicon-edit"></i> 修改</a>
                                <button type="button" class="btn  btn-danger btn-xs"  data-toggle="modal" data-target="#modal{{$activity->id}}"><i class="icon  glyphicon glyphicon-remove"></i> 删除</button>

                                <div id="modal{{$activity->id}}" class="modal fade">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                <h4 class="modal-title">删除警告:</h4>
                                            </div>
                                            <div class="modal-body">
                                                <p>确认要删除活动[{{$activity->name}}]吗?</p>
                                            </div>
                                            <div class="modal-footer">



                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                                <button type="submit" class="btn btn-danger01" itemid="{{$activity->id}}">删除</button>


                                            </div>
                                        </div><!-- /.modal-content -->
                                    </div><!-- /.modal-dialog -->
                                </div><!-- /.modal -->

                            </td>
                        </tr>
                        @endforeach
                    </table>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <div class="pull-right no-margin-pager">
                        {!! $activitys->render() !!}
                    </div>

                    {!! Form::hidden('_method', 'POST') !!}
                    <button type="submit" class="btn btn-success"> 排序</button>
                </div>
                <!-- /.box-footer -->
            </div>
            <!-- /.box -->
            {!! Form::close()  !!}

        </div>
    </div>



</section>
<!-- /.content -->

<script >
    $('.is_recommend').on('click',function(){
        var el = $(this);
        var id = el.attr('id');
        var url = "{{Route('admin.activity.toggleShow')}}";
        $.ajax({
            url:url+"/?id="+id,
            type:'get',
            dataType:'json',
            success:function(result){
                if(result.info){
                    if(result.is_recommend==1){
                        el.find('.glyphicon').removeClass('glyphicon-remove');
                        el.find('.glyphicon').addClass('glyphicon-ok');
                        el.find('.glyphicon').css("color","green");

                    }else{
                        el.find('.glyphicon').removeClass('glyphicon-ok');
                        el.find('.glyphicon').addClass('glyphicon-remove');
                        el.find('.glyphicon').css("color","red");

                    }

                }
            }
        });
    });

</script>

<script>

        $('.btn-danger01').on('click',function(e){
            e.preventDefault();
            var id = $(this).attr("itemid");
            //alert(id);
            if(!id) return false;

            $.ajax({
                url:'/admin/activity/'+id+"?"+Math.random(),
                type:'delete',
                data:{id:id,'_token':'{{csrf_token()}}'},
                dataType:"json",
                success:function(result){                    

                    if(result.status){
                        $('#del_alert').modal();
                        $("#ok").hide();
                        $("#no").show();
                        $("#message_content").html(result.info);
                    }else{
                        window.location.reload();
                    }

                }

            });

        });      
        
        
    </script>

<script>
    $('.btn-danger').on('click',function(){
        console.log('11');
    });
</script>
@endsection